package com.example.crm.servlet;

import com.example.crm.service.IUserService;
import com.example.crm.service.impl.UserServicelmpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lazyfier
 */
@WebServlet("/loginchk")
public class UserLoginCheckServlet extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 1. 获取用户请求信息
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username+":"+password);

        // 2. 调用service查询
        IUserService service = new UserServicelmpl();
        boolean result = service.login(username, password);

        // 3. 打印结果 / 跳转页面 / 请求转发
        if(result)
        {
            System.out.println("登录成功");
            resp.sendRedirect("index.jsp");
        }
        else
        {
            System.out.println("登录失败");
            resp.sendRedirect("login.jsp");
        }

    }
}
